﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SongsDB;
using System.Collections.Generic;

namespace WIMMP.BLL
{
    public class Player
    {
        SDBPlayer player;
        List<Song> nowPlaying;


        public string CurrentSong
        {
            get
            {
                return player.CurrentSong.ArtistName + " - " + player.CurrentSong.Title;
            }
        }

        public List<Song> NowPlaying
        {
            get
            {
                return nowPlaying;
            }
        }


        public int CurrentSongIndex
        {
            get
            {
                return player.CurrentSongIndex;
            }
        }

        public Player()
        {
            SongsDB.SDBApplication sdb = new SongsDB.SDBApplication();
            sdb.ShutdownAfterDisconnect = false;
            sdb.OnPlay += new ISDBApplicationEvents_OnPlayEventHandler(sdb_OnPlay);
            sdb.OnTrackEnd += new ISDBApplicationEvents_OnTrackEndEventHandler(sdb_OnTrackEnd);
            
            player = sdb.Player;


            nowPlaying = new List<Song>();

            for (int i = 0; i < player.CurrentSongList.Count; i++)
            {
                SDBSongDataClass tempSdbSong = (SDBSongDataClass)player.CurrentSongList.get_Item(i);
                Song tempSong = new Song(i, tempSdbSong);
                nowPlaying.Add(tempSong);
            }

        }

        void sdb_OnTrackEnd()
        {
            string foo = "bar!";
        }

        void sdb_OnPlay()
        {
            string foo = "bar!";
        }




        public void Next()
        {
            player.Next();
        }
        public void Prev()
        {
            player.Previous();
        }
        public void Pause()
        {
            player.Pause();
        }

    }
}
